Skip to content

Units::teleport: update occupancy for the full EQUIPMENT footprint - #5924

Merged
ab9rf merged 2 commits into
DFHack:developfrom
Alistair-Afton:fix-teleport-wagon-occupancy
Sep 17, 2026
Merged

ab9rf merged 2 commits into
DFHack:developfrom
Alistair-Afton:fix-teleport-wagon-occupancy

Conversation

@Alistair-Afton

Copy link
Copy Markdown
Contributor

Fixes #5797

Summary

Units::teleport only cleared and set the unit/unit_grounded occupancy bits on the unit's center tile. EQUIPMENT units such as wagons occupy a 3x3 footprint centered on their position, so a teleported wagon left stale flags on the eight surrounding source tiles and arrived with none set on the destination footprint.

The footprint extent is now derived from the race's EQUIPMENT_WAGON flag; ordinary units keep the existing single-tile behavior. The per-tile update logic is otherwise unchanged.

Testing

Verified in a live fort against the rebuilt install by driving a synthetic wagon unit (race EQUIPMENT_WAGON) through dfhack.units.teleport and reading map_block.occupancy directly:

  • Teleport A->B: all 9 source tiles cleared, all 9 destination tiles set. Previously only the center tile was updated in both directions.
  • Regression check with a real dwarf: only the single position tile is cleared/set, unchanged from before.

EQUIPMENT units (wagons) occupy a 3x3 footprint centered on their
position, but teleport only cleared and set the unit occupancy bits on
the center tile. Teleported wagons left stale unit flags on the eight
surrounding source tiles and arrived with none set on the destination
footprint, leaving the map occupancy inconsistent until something
recomputed it (issue DFHack#5797).

The footprint extent now comes from the race's EQUIPMENT_WAGON flag, so
ordinary units keep the existing single-tile behavior.
@Alistair-Afton
Alistair-Afton force-pushed the fix-teleport-wagon-occupancy branch from de2b52e to 3a250e0 Compare September 17, 2026 14:31
@ab9rf

ab9rf commented Sep 17, 2026

Copy link
Copy Markdown
Member

Holding this one until we know (from reverse engineering) whether the equipment flag is the correct way to infer that a unit has a 3x3 occupancy footprint

@ab9rf

ab9rf commented Sep 17, 2026

Copy link
Copy Markdown
Member

Holding this one until we know (from reverse engineering) whether the equipment flag is the correct way to infer that a unit has a 3x3 occupancy footprint

Verified that this is correct. teleport does incorrectly clear unit_grounded when there is another grounded unit in the same tile, but this was a preexisting defect in teleport and I'm not going to hold this PR up over that defect.

@ab9rf
ab9rf merged commit 7ed65fa into DFHack:develop Sep 17, 2026
14 checks passed

@SilasD SilasD left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this one already got approved, but I do have a question.

(someday I'll learn the difference between commenting and reviewing. yesterday was not that day; it seems today isn't either.)

Comment thread library/modules/Units.cpp
Comment on lines 816 to 818
// If there's already somebody standing at the destination, then force the unit to lay down
if (new_occ->bits.unit)
unit->flags1.bits.on_ground = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this not also iterate over for_each_occupied_tile to see if any of the 1 (normally) or 9 (EQUIPMENT) tiles has a standing unit?
so that if there's a standing unit in any of the 9 tiles, the wagon arrives laying down.
coffee hasn't kicked in, so I'd like a second opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Units::teleport does not correctly handle Wagons

3 participants